package com.wanxi.servlet.area;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.ServiceTypeModel;
import com.wanxi.service.Impl.ServiceTypeServiceImpl;
import com.wanxi.service.ServiceTypeService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/7 19:21
 */
@WebServlet("/back/FindAreaById")
public class FindAreaByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //乱码解决
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        //接收前端值
        String id = req.getParameter("id");;
        //封装model
        ServiceTypeModel serviceTypeModel = ServiceTypeModel.builder()
                .id(Tool.nullToInt(id))
                .build();
        //调用service层
        ServiceTypeService serviceTypeService = new ServiceTypeServiceImpl();
        ResultDto resultDto = serviceTypeService.findById(serviceTypeModel);
        //返回前端数据
        resp.getWriter().println(JSONObject.toJSONString(resultDto));
    }
}
